package com.example.test.享元模式;

import cn.hutool.core.util.RandomUtil;
import com.example.test.bean.User;

import java.util.HashMap;
import java.util.Map;

public class XYFactory {

    Map<Integer, User> map = new HashMap<>();

    public User getUser(Integer num) {
        User user = map.get(num);
        if (user == null) {
            user = new User();
            map.put(RandomUtil.randomInt(9), user);
        }

        return user;
    }

}
